package com.sevlet;

import com.Bean.PaymentTerm;
import com.dao.impl.CheckInDaoImpl;
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import com.util.JsonUtil;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;
import java.sql.SQLException;
import java.util.List;
@WebServlet("/PaySevlet")
public class PaySevlet extends BaseSevlet{
    public void selectPayType(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        resp.setContentType("text/html;charset=utf-8");
        Gson gson = new GsonBuilder().create();
        JsonUtil jsonUtil = new JsonUtil();
        CheckInDaoImpl checkInDao = new CheckInDaoImpl();
        PrintWriter writer =null;
        try {
            writer = resp.getWriter();
            List<PaymentTerm> paymentTerms = checkInDao.SelectPayType();
            jsonUtil.setCode(0);
            jsonUtil.setMsg("成功");
            jsonUtil.setData(paymentTerms);
        } catch (SQLException throwables) {
            throwables.printStackTrace();
            jsonUtil.setCode(1);
            jsonUtil.setMsg("系统错误");
        }finally {
            if (writer!=null){
                writer.print(gson.toJson(jsonUtil));
            }
        }
    }
}
